package com.example.applicationnews;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;

public class NewsDetailActivity extends AppCompatActivity {
    private String news_url;
    private WebView webView;
    private final long exitTime = 0;
    private TextView textView;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_detail);
        textView = findViewById(R.id.detail_title);
        webView = findViewById(R.id.webview);
        webView.setWebViewClient(new WebViewClient() {
            // 设置在webView点击打开的新网页在当前界面显示,而不跳转到新的浏览器中
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        // 设置WebView属性,运行执行js脚本
        webView.getSettings().setJavaScriptEnabled(true);
        Bundle bundle = this.getIntent().getExtras();
        news_url = bundle.getString("url");
        // 调用loadUrl方法为WebView加入链接
        webView.loadUrl(news_url);
        // 调用Activity提供的setContentView将webView显示出来
        textView.setText(bundle.getString("type"));
    }
}